package com.pubinfo.passbook.engine.process.variable.medicine;

import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.model.ruler.PayInformation;
import com.pubinfo.passbook.common.service.ruler.InformationService;
import com.pubinfo.passbook.engine.utils.ApplicationContextUilts;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.List;

/**
 * 自负金额总数获取
 *
 * @author zhouch
 * @date 2022/1/27 10:49
 */
@Slf4j
public class SelfpaymentAmountsProcessor extends MedicineVariableProcessor {

    @Override
    public String getName() {
        return "自负金额总数";
    }

    @Override
    public BigDecimal get(MedicineOnJobOrRetireDTO data) {

        log.info("执行参数处理器: {}", this.getClass().getSimpleName());

        List<PayInformation> payInformations = cache.getPayInformationData();

        BigDecimal selfpaymentAmounts = new BigDecimal(0);

        for (PayInformation payInformation : payInformations) {

            //自负总金额
            //获取自负项目总数
            BigDecimal selfpaymentAmount = payInformation.getSelfpaymentAmount();
            if (selfpaymentAmount.equals(new BigDecimal(-0.0000999))) {
                cache.markNeedAudit();
                log.info("{} ==> 需要人工审核.", getClass().getSimpleName());
                selfpaymentAmount = BigDecimal.ZERO;
            }
            selfpaymentAmounts = selfpaymentAmounts.add(selfpaymentAmount);

        }

        log.info("参数处理器: {} 结果: {}", this.getClass().getSimpleName(), selfpaymentAmounts);

        outputComputeMessage(selfpaymentAmounts.toString());

        return selfpaymentAmounts;
    }
}
